import request from "@/util/request";

const topoType = ["static", "rip", "ospf"];

export function getAllTopo() {
  return request({
    url: "/topology/config/all",
    method: "get",
    params: {},
  });
}

export function getTopoById(id) {
  return request({
    url: "/topology/config",
    method: "get",
    params: {
      configId: id,
    },
  });
}

export function addTopo(info) {
  console.log("[[ info ]]", info, typeof info);
  console.log("[[ JSON.parse(info) ]]", JSON.parse(info));
  let type =
    typeof info === "string" ? JSON.parse(info).topotype : info.topoType;
  
  return request({
    url: "/topology/config",
    method: "post",
    params: {
      topo: topoType.indexOf(type),
    },
    data: info,
  });
}

export function delTopo(id) {
  return request({
    url: "/topology/config",
    method: "delete",
    params: {
      configId: id,
    },
  });
}

export function applyTopo(id) {
  return request({
    url: "/topology/config/apply",
    method: "post",
    params: {
      configId: id,
    },
  });
}

export function checkTopo(type) {
	console.log(type, topoType.indexOf(type));
  return request({
    url: "/topology/config/check",
    method: "post",
    params: {
      topo: topoType.indexOf(type),
    },
  });
}
